package com.cloud.order.controller;

import com.cloud.order.entity.Order;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Value("${spring.cloud.client.ip-address}")
    private String ip;

    @Value("${server.port}")
    private String port;

    @GetMapping("{id}")
    public Map findById(@PathVariable Integer id){

        return new HashMap(){{
            put("flag",true);
            put("message","查询成功"+ip+":"+port);
            put("statusCode","200");
            put("id",id);
        }};
    }

    /**
     * 新增订单
     * @param order
     * @return
     */
    @PostMapping
    public Map save(@RequestBody Order order){

        return new HashMap(){{
            put("flag",true);
            put("message","新增成功");
            put("statusCode","200");
            put("order",order);
        }};
    }

    /**
     * 删除订单
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Map delete(@PathVariable Integer id){

        return new HashMap(){{
            put("flag",true);
            put("message","删除成功");
            put("statusCode","200");
            put("id",id);
        }};
    }

    /**
     *
     * @param id
     * @param order
     * @return
     */
    @PutMapping("{id}")
    public Map update(@PathVariable Integer id,@RequestBody Order order){

        order.setId(id);
        return new HashMap(){{
            put("flag",true);
            put("message","修改");
            put("statusCode","200");
            put("order",order);
        }};
    }

}
